package com.phospherus.customerinfo.controller;

import com.phospherus.common.controller.handler.ResultHandler;
import com.phospherus.customerinfo.entity.BaseMessage;
import com.phospherus.customerinfo.service.ICreditReportService;
import com.phospherus.customerinfo.service.IQichachaCompanyInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * Created by lipeng on 17/11/13
 */
@Controller
@RequestMapping("/cusinfo")
public class CustomerInfoController {
    @Autowired
    private IQichachaCompanyInfoService service;
    @Autowired
    private ICreditReportService creditReportService;

    /**
     * 获取公司基本信息
     * @param param 公司详细名称
     * @return 综合消息体
     */
    @ResponseBody
    @RequestMapping(value="/baseinfo")
    public ResultHandler getBaseInfo(@RequestParam Map<String, String> param){
        BaseMessage message = null;
        if(param!=null&&param.size()==1){
            try {
                message  = service.getDetailsByName(param.get("name"));
            }catch (Exception ex){
                ex.printStackTrace();
                message = new BaseMessage();
            }

        }
        return new ResultHandler(ResultHandler.SystemMessage.SUCCESS,message);
    }

    /**
     * 获取信用报告地址
     * @param param 公司keyNO
     * @return 综合消息体
     */
    @ResponseBody
    @RequestMapping(value="/getReport")
    public ResultHandler getCreditReport(@RequestParam Map<String, String> param){
        BaseMessage message = null;
        if(param!=null&&param.size()==1){
            try {
                message  = creditReportService.getCreditReport(param.get("keyno"));
            }catch (Exception ex){
                ex.printStackTrace();
                message = new BaseMessage();
            }

        }
        return new ResultHandler(ResultHandler.SystemMessage.SUCCESS,message);
    }

}
